﻿using ConfExpert.Forms.Araclar;
using ConfExpert.Forms.Base;
using ConfExpert.Forms.Depo;
using ConfExpert.Forms.Depo._7C;
using ConfExpert.Forms.Depo.Westbrook;
using ConfExpert.Forms.ImportWizards;
using ConfExpert.Forms.ImportWizards.Siparis;
using ConfExpert.Forms.Lojistik;
using ConfExpert.Forms.Satinalma;
using ConfExpert.Forms.SatinAlma;
using ConfExpert.Forms.Siparisler;
using ConfExpert.Forms.Sistem.Conversion;
using ConfExpert.Utility;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraNavBar;
using DevTeam;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.DockingControls
{
    public class CustomerBasedOperations : DockingControlBase
    {
        public CustomerBasedOperations(NavBarControl navBar, GridLookUpEdit gleCustomer)
        {
            NavigationBar = navBar;
            Lookup = gleCustomer;

            NavigationBar.Groups.Clear();


            /*
             * ÖNEMLİ: bu şekilde kullanıldığında filtre programdaki tüm customer lookup'larını etkiliyor!
             * 
            string filter = "CustomerId in (42,68,22) ";
            DataView dv = AppSession.Lookups.V_Customer.DefaultView;
            dv.RowFilter = filter;
            */
            XForm x = new XForm();
            //DataTable dt = Session.DataManager.ExecuteDataTable("GetCustomersForBaseForm");
            //RepositoryItemGridLookUpEdit riCustomer = x.GetCustomGLE(dt, "Name", "CustomerId");     //OA.2

            DataTable dt = Session.DataManager.ExecuteDataTable("GetMyCustomers2", Session.CurrentUser.UserId);
            dt.Columns.RemoveAt(2); //cari
            RepositoryItemGridLookUpEdit riCustomers = x.GetCustomGLE(dt, "Name", "CustomerId");
            Lookup.Properties.Assign(riCustomers);


            //XForm x = new XForm();
            //DataTable dtPODurumTela = AppSession.Lookups.PODurum.Select("PODurumId in(1,6,7)").CopyToDataTable();
            //RepositoryItemGridLookUpEdit riPODurumTela = x.GetCustomGLE(dtPODurumTela, "Name", "PODurumId");
            //gridView1.Columns["PODurumId"].ColumnEdit = riPODurumTela;


            //Lookup.Properties.PopupFilterMode = PopupFilterMode.Contains;
            //Lookup.Properties.View.Columns["Name"].OptionsFilter.AutoFilterCondition = AppSession.Settings.AutoFilterCondition == "Contains" ? AutoFilterCondition.Contains : AutoFilterCondition.Like;
            //Lookup.Properties.Assign(x.RI(Rp.V_Customer));
            //Lookup.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            //gleCustomer.EditValue = AppSession.Lookups.V_Customer.Rows[0]["CustomerId"];

            gleCustomer.EditValueChanged += delegate { Refresh(); };

            if (AppSession.gleCustomer > 0)
                Lookup.EditValue = AppSession.gleCustomer;
        }

        public void Refresh()
        {
            NavBarGroup group;
            NavigationBar.Groups.Clear();

            if (Lookup.EditValue != null)
            {
                int CustomerId = (int)Lookup.EditValue;
                AppSession.gleCustomer = CustomerId;

                switch (CustomerId)
                {
                    case 42:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", ImportKauf);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Model Fiyatları", typeof(Depo.Kauf.GomlekFiyati));
                        AddMenuItem(group, "Çıkış Emirleri", typeof(Depo.Kauf.CikisEmirleri));
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        //AddMenuItem(group, "Bloke Koy", typeof(Depo.BlokeKoy), CustomerId);
                        AddMenuItem(group, "Gömlek Etiketleri", typeof(AdhocQuery), AdhocQuery.AdHocQueries.KaufGomlekEtiketi);
                        AddMenuItem(group, "Gömlek Etiketleri.2", typeof(Depo.Kauf.GomlekEtiketi2), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);

                        group = AddGroup("Muhasebe");
                        AddMenuItem(group, "Fatura Dosyası Aktarımı", typeof(Forms.ImportWizards.Invoice.Du4));

                        if (Session.CurrentUser.AmI(53))
                            AddMenuItem(group, "Mal sahibi değişikliği", typeof(MalsahibiDegistir));

                        break;

                    case 68: //Texcomm
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", ImportTexcomm);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Düğme Kodları", typeof(Depo.Texcomm.Dugme));
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;

                    case 22:    //DU4
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", ImportDU4);
                        AddMenuItem(group, "Artikeller", typeof(Depo.Du4Articles));
                        AddMenuItem(group, "Mükerrer Artikeller", typeof(Du4.Mukerrer));
                        AddMenuItem(group, "Siparişler", typeof(Du4.Orders));
                        AddMenuItem(group, "Model Fiyatları", typeof(Du4.GomlekFiyati));
                        AddMenuItem(group, "Toplar", typeof(AdhocQuery), AdhocQuery.AdHocQueries.Du4DepodakiToplar);
                        AddMenuItem(group, "Eksik Kumaşlar", typeof(Du4.Missing));
                        AddMenuItem(group, "Stok Durumu", typeof(Du4.StokDurumu));
                        AddMenuItem(group, "Kesim Geçmişi", typeof(Du4.KesimGecmisi));
                        AddMenuItem(group, "Raf Yerleştirme", typeof(Depo.Yerlestirme));
                        AddMenuItem(group, "Dosya Adet Raporu Yerleştirme", typeof(AdhocQuery), AdhocQuery.AdHocQueries.Du4DosyaBazindaKesimAdetleri);
                        AddMenuItem(group, "Gömlek Etiketleri", typeof(AdhocQuery), AdhocQuery.AdHocQueries.Du4GomlekEtiketi);

                        if (Session.CurrentUser.UserId == 53 || Session.CurrentUser.UserId == 78)
                            AddMenuItem(group, "Kart Birleştir", typeof(Du4.MergeCards));

                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        //AddMenuItem(group, "Bloke Koy", typeof(Depo.BlokeKoy), CustomerId);

                        group = AddGroup("Muhasebe");
                        AddMenuItem(group, "Fatura Dosyası Aktarımı", typeof(Forms.ImportWizards.Invoice.Du4));

                        break;

                    case 75:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Siparişler", typeof(Depo.Westbrook.Orders));
                        AddMenuItem(group, "Modeller", typeof(Depo.Westbrook.Styles));
                        AddMenuItem(group, "Modeller(Türkçe)", typeof(Depo.Westbrook.StylesTR));
                        AddMenuItem(group, "EN-TR Çeviri", typeof(Depo.Westbrook.Ref));
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Westbrook.StokDurumu));
                        AddMenuItem(group, "Fiyatlar", typeof(Depo.Westbrook.Fiyatlar));
                        AddMenuItem(group, "ConfOrder Kumaş Siparişleri", typeof(ArticleOrders));
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);

                        group = AddGroup("Müşteri Çalışmaları");
                        AddMenuItem(group, "Modeller", typeof(Depo.Westbrook.COStyle));
                        AddMenuItem(group, "Siparişler", typeof(Depo.Westbrook.COOrder));
                        AddMenuItem(group, "Sold Quantities", typeof(SoldQuantitiesPOS));
                        break;

                    case 20:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", typeof(NewOrder));
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        //AddMenuItem(group, "Dönmesi Beklenen Kumaşlar", typeof(DonmesiBeklenenKumaslar));
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        AddMenuItem(group, "Çıkılan toplar", typeof(CikilanToplar));

                        if (Session.CurrentUser.AmI(4, 7, 17, 67))
                            AddMenuItem(group, "Etkileşimli Sipariş", typeof(Siparisler.InteractiveOrder));

                        AddMenuItem(group, "Metraj karşılaştırması", typeof(Metrajlar));

                        group = AddGroup("Barkod");
                        AddMenuItem(group, "Barkod Dosyası - Tekil", typeof(ImportWizards.GP_7C_Tip1));
                        AddMenuItem(group, "Barkod Dosyası", typeof(Lojistik.GP_7C_Tip2));
                        if (Session.CurrentUser.AmI(17))
                            AddMenuItem(group, "Dosya Upload", typeof(UploadBarkod));

                        //AddMenuItem(group, "*Barkod Merge", BarkodMerge7c);
                        AddMenuItem(group, "Koli Üstü", typeof(ImportWizards.Koliustu.GP));
                        AddMenuItem(group, "Çeki listesi Tip #1", typeof(GP_7C_Tip_1));

                        group = AddGroup("Kodlar");
                        AddMenuItem(group, "Beden-Garni kodları", typeof(EskiYeniKod), "GpBedenGarni", CustomerId);
                        //AddMenuItem(group, "Eski-Yeni kodlar", typeof(EskiYeniKod), "YeniKodlar", CustomerId);
                        break;

                    case 149: // CafeCoton
                        //AddMenuItem(group, "Ara Sezon Siparişleri", typeof(CafeCotton_Tip2));

                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", typeof(CafeCotton_Tip2));
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        //AddMenuItem(group, "Otomatik Stok Girişi", typeof(ImportWizards.CafeCoton_Tip1));
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);

                        // group.AddMenu("7C Çeki", Resources.BO_Task_32x32, typeof(Ceki7C));
                        group = AddGroup("Diğer");
                        AddMenuItem(group, "Koli Üstü Etiketi", typeof(ImportWizards.Koliustu.CafeCoton));
                        AddMenuItem(group, "Barkod Etiketi", typeof(Lojistik.CafeCoton.Barkod), 339);
                        AddMenuItem(group, "Barkod Dosyası Yükle", typeof(Lojistik.CafeCoton.BarkodDosyasiYukle), 339);
                        AddMenuItem(group, "Barkod Dosyası Yükle- Order'a göre", typeof(Lojistik.CafeCoton.BarkodDosyasiYukle2), 339);
                        //AddMenuItem(group, "Barkod Listesi", typeof(Depo.Barkod), 339);
                        //AddMenuItem(group, "Barkod Listesi- Özet", typeof(Depo.BarkodPivot_Yeni), 339);

                        //AddMenuItem(group, "Dönen Gömleklerin Barkodu", typeof(CC_Barkod));
                        //AddMenuItem(group, "Dönen Gömleklerin Çeki listesi", typeof(CC_Ceki));
                        //AddMenuItem(group, "Barkod", typeof(ImportWizards.Barkod.CafeCotton));

                        break;
                    case 178:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", typeof(Hackett_Tip1));
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;

                    case 25:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", ImportKauf);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Gömlek Etiketleri", typeof(AdhocQuery), AdhocQuery.AdHocQueries.ElshofGomlekEtiketi);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;

                    case 200:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", ImportKauf);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);

                        AddMenuItem(group, "Sayfa birleştirme", typeof(Consolidate2));
                        AddMenuItem(group, "Format değiştirme", typeof(Saks));
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;

                    case 366:   //Zegna
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", ImportZegna);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;

                    case 96:   //GIANNI VERSACE SPA
                        group = AddGroup("Genel");
                        //AddMenuItem(group, "Sipariş Dönüşümü", ImportVersace);
                        AddMenuItem(group, "Sipariş Aktarımı", typeof(SiparisAktar), CustomerId);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;

                    case 17:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", typeof(SiparisAktar), 17);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;

                    case 241:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", typeof(XIHolyFashion));
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        AddMenuItem(group, "Koli Üstü", typeof(KoliUstuHF));
                        AddMenuItem(group, "Sipariş Aktarımı-Numune", typeof(XIHolyFashionNumune));
                        break;

                    default:
                        group = AddGroup("Genel");
                        AddMenuItem(group, "Sipariş Aktarımı", ImportKauf);
                        //AddMenuItem(group, "Sipariş Aktarımı", typeof(SiparisAktar), CustomerId);
                        AddMenuItem(group, "Siparişler", typeof(Depo.Kauf.Orders), CustomerId);
                        AddMenuItem(group, "Stok Durumu", typeof(Depo.Kauf.StokDurumu), CustomerId);
                        AddMenuItem(group, "Model Detayları", typeof(Depo.Kauf.ModelDetaylari), CustomerId);
                        AddMenuItem(group, "Birim Metrajlar", typeof(Depo.Kauf.BirimMetrajlar), CustomerId);
                        AddMenuItem(group, "Sipariş formu sütun düzenle", typeof(GM_Init2), CustomerId);
                        break;
                }

                if (CustomerId == 306)
                {
                    AddMenuItem(group, "Gentiluomo Yıkama Talimatı", typeof(Aksesuar.YikamaTalimati), "GetGentiluomoYikamaTalimatlari");
                }

                if (CustomerId != 20)
                    AddMenuItem(group, "Beden Dağılım Trendi", typeof(ConfExpert.Forms.Siparisler.BedenDagilim), CustomerId);

                AddMenuItem(group, "Muadil kodlar", typeof(MuadilKodlar), CustomerId);
                AddMenuItem(group, "Müşteri Kodu düzenle/birleştir", typeof(MKMerge), CustomerId);
                AddMenuItem(group, "Tela Fazla Çıkış Oranı", typeof(Depo.Kauf.TelaFarkOranı), CustomerId);
                AddMenuItem(group, "Aksesuar Planlama", typeof(Depo.Aksesuar.AksesuarPlanlama), CustomerId);
                AddMenuItem(group, "Fazla Kesim Aksesuar İhtiyacı", typeof(Depo.Kauf.FazlaKesim), CustomerId);

                if (CustomerId == 241)
                {
                    group = AddGroup("BOM");
                    AddMenuItem(group, "BOM Import", typeof(Siparisler.BOM.HolyFashion));
                    AddMenuItem(group, "BOMs", typeof(Depo.Kauf.BOMs), CustomerId);
                    AddMenuItem(group, "BOM Eşleme", typeof(Depo.Kauf.BOMEsleme), CustomerId);
                }


                //group = AddGroup("Yükleme Bilgi Formu");
                //AddMenuItem(group, "Yeni Oluştur", typeof(YuklemeFormu), CustomerId);
                //AddMenuItem(group, "Liste", typeof(YuklemeFormlari), CustomerId);

            }
        }



        void ImportDU4()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DataTable dt = ConfExpert.Forms.Sistem.Conversion.DU4Yeni2.Convert(Enums.ProcessMethod.XlsFile, openFileDialog1.FileName);

                using (Import i = new Import("DU4Orders", dt))
                    if (i.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        if (i.Dupl == string.Empty)
                            AppSession.MainForm.NotifyMain("Başarı ile aktarıldı.");
                        else
                            XtraMessageBox.Show(i.Dupl, "Şu satırlar daha önce aktarıldığı için bu aktarım gerçekleşmedi.");
            }
        }

        void ImportTexcomm()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DataTable dt = ConfExpert.Forms.Sistem.Conversion.Texcomm.Convert(Enums.ProcessMethod.XlsFile, openFileDialog1.FileName);

                using (Import i = new Import("TexcommOrders", dt))
                    if (i.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        AppSession.MainForm.NotifyMain("Başarı ile aktarıldı.");
            }
        }

        void ImportKauf()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DataTable dt = ConfExpert.Forms.Sistem.Conversion.Kauf.Convert(Enums.ProcessMethod.XlsFile, openFileDialog1.FileName);

                using (Import i = new Import("Orders", dt, AppSession.gleCustomer))
                    if (i.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        AppSession.MainForm.NotifyMain("Başarı ile aktarıldı.");
            }
        }

        void ImportZegna()
        {
            using (Zegna i = new Zegna())
                if (i.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    AppSession.MainForm.NotifyMain("Başarı ile aktarıldı.");
        }

        void BarkodMerge7c()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                DataTable dt = ConfExpert.Forms.Sistem.Conversion._7cBarkod.Convert(Enums.ProcessMethod.XlsFile, openFileDialog1.FileName);

                using (_7cbarkodlist i = new _7cbarkodlist(dt))
                    i.ShowDialog();
            }
        }
    }
}